﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Text.RegularExpressions;

/// <summary>
///MyApp 的摘要说明   **********这里主要存放自定义的全局函数
/// </summary>

//
//*************************所有自定义的转换函数放在这个类里***********************
//
public class ZhuanHuan
{
    /*字符串转浮点型，解决当字符串是空串时转换出错的问题,能排除中文字符，包括排除错将句号当小数点的情况
           当str不是有效数字的字符串是，结果返回0 */
    public double StrToDouble(string str)
    {
            
        
        double fs = 0;
        str = str.Trim();
        if (str != null && Regex.IsMatch(str, @"^(([0-9]+[\.]?[0-9]+)|[1-9])$"))
        {
            fs =  double.Parse(str.Trim());
        }
        return fs;
    }
}



//
//*********************************自定义的一些应用函数*******************************************
//
public class YingYongHanShu
{

    //界面提示框的DisplayStr函数
    public string DisplayStr2(string biaoid)
    {
        SqlConnection sqlcon = new SqlConnection();
        sqlcon.ConnectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
        sqlcon.Open();

        SqlCommand sqlcmd1 = new SqlCommand("select * from tishi where substring(tishiid,1,6)='" + biaoid + "'", sqlcon);
        //reader.Close();
        //sqlcon.Open();
        SqlDataReader reader1 = sqlcmd1.ExecuteReader(CommandBehavior.CloseConnection);
        string joinstr = "[";
        while (reader1.Read())
        {
            joinstr = joinstr + "{'tishiid':'" + reader1["tishiid"].ToString() + "','idmingcheng':'" + reader1["idmingcheng"].ToString() + "','ti1':'" + reader1["ti1"].ToString() + "','ti2':'" + reader1["ti2"].ToString() + "','ti3':'" + reader1["ti3"].ToString() + "'},";
        }

        joinstr = joinstr.Substring(0, joinstr.Length - 1);
        joinstr = joinstr + "]";

        reader1.Close();
        sqlcon.Close();
        if (joinstr=="]")
        {
            joinstr = "[{'tishiid':'','idmingcheng':'','ti1':'','ti2':'','ti3':''}]";  
        }

        return joinstr;

    }


    public string DisplayStrsh(string biaoid)
    {
        SqlConnection sqlcon = new SqlConnection();
        sqlcon.ConnectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
        sqlcon.Open();

        SqlCommand sqlcmd1 = new SqlCommand("select * from ShenHeTiShi where substring(ShenHetishiid,1,6)='" + biaoid + "'", sqlcon);
        //reader.Close();
        //sqlcon.Open();
        SqlDataReader reader1 = sqlcmd1.ExecuteReader(CommandBehavior.CloseConnection);
        string joinstr = "[";
        while (reader1.Read())
        {
            joinstr = joinstr + "{'shenhetishiid':'" + reader1["shenhetishiid"].ToString() + "','idmingcheng':'" + reader1["idmingcheng"].ToString() + "','tishineirong':'" + reader1["tishineirong"].ToString() + "'},";
        }

        joinstr = joinstr.Substring(0, joinstr.Length - 1);
        joinstr = joinstr + "]";

        reader1.Close();
        sqlcon.Close();
        if (joinstr == "]")
        {
            joinstr = "[{'shenhetishiid':'','idmingcheng':'','tishineirong':''}]";
        }

        return joinstr;

    }




}